package com.rotsel.mh3udb.app.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.rotsel.mh3udb.app.R;
import com.rotsel.mh3udb.app.ListModels.IdNameModel;

import java.util.ArrayList;

/**
 * Created by rots on 31.01.14.
 */
public class IdNameAdapter extends ArrayAdapter<IdNameModel> {
    private final Context context;
    private final ArrayList<IdNameModel> modelArrayList;

    public IdNameAdapter(Context cont, ArrayList<IdNameModel> list){
        super(cont, R.layout.text_list_item, list);

        this.context = cont;
        this.modelArrayList = list;
    }

    @Override
    public long getItemId(int position) {
        return modelArrayList.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.text_list_item, parent, false);

        TextView txtView = (TextView)rowView.findViewById(R.id.item_text);
        txtView.setText(modelArrayList.get(position).getName());

        return rowView;
    }
}
